fix(form-core): clear stale onBlur errors on re-submission#2120
Conversation
…errors When a field has an onBlur validator that produces an error, subsequent form submission attempts are blocked by a canSubmit check that runs before validateAllFields. This means stale onBlur errors (e.g. from a field that is no longer invalid) prevent re-submission. Fix: on re-submission attempts (submissionAttempts > 1), skip the early canSubmit return so validateAllFields can re-run all field validators for the submit cause. Stale errors are cleared and the isFieldsValid check below handles the invalidity gate correctly. First-submission behavior (submissionAttempts <= 1) is unchanged so existing canSubmit semantics (e.g. onMount errors) are preserved. Fixes TanStack#2034
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughUpdated Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
For context: This is actually fixing a nasty bug that cost us an App Review submission cycle. Would love to see a maintainer take a look. |
|
View your CI Pipeline Execution ↗ for commit bdd4fc0
☁️ Nx Cloud last updated this comment at |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2120 +/- ##
==========================================
- Coverage 90.35% 89.71% -0.64%
==========================================
Files 38 65 +27
Lines 1752 3200 +1448
Branches 444 804 +360
==========================================
+ Hits 1583 2871 +1288
- Misses 149 295 +146
- Partials 20 34 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Changes
Fixes #2034
When a field has an
onBlurvalidator that produces an error, subsequent submit attempts get blocked. ThecanSubmitcheck in_handleSubmitreturns early beforevalidateAllFieldshas a chance to re-run and clear the stale error.This patch skips the early return on re-submission (
submissionAttempts > 1) so thatvalidateAllFieldsactually runs again. First-submission behavior is unchanged.Added a regression test that reproduces the exact scenario from the issue — conditional field validation with type switching.
Checklist
pnpm test:pr.Release Impact
Summary by CodeRabbit
Bug Fixes
Tests
Chores